
--[[
过滤器应用模块，需要在nginx配置文件中定义应用路径：APP_PATH。
应用过滤器的配置文件路径：APP_PATH/config/filter.lua
--]]
local util_file = require("luastar.util.file")
----local logger=logger;
local Filter = Class("com.ea.core.Filter")

function Filter:init(config_file)
    if ngx.var.APP_DEBUG_LOG== "true" then ngx.log(ngx.DEBUG, logger.formatMsg("[Filter:init] file : ", config_file)) end
    self.config_file = config_file
    if not self.config_file then
        ngx.log(ngx.ERR, logger.formatMsg("[Filter:init] illegal argument : config_file can't nil."))
        return
    end
    local config = util_file.loadlua(self.config_file)
    -- 初始化过滤器配置
    self.config_filter = config["filter"] or {}
     for i, val in ipairs(self.config_filter) do   
            if ngx.var.APP_DEBUG_LOG== "true" then ngx.log(ngx.DEBUG,logger.formatMsg(string.format("index=%s ,class=%s,method=%s",i,val["class"],val["method"])))      end
           -- table.insert(retVal,{ class = val[1], method = val[2] })       
    end
    ngx.log(ngx.INFO, logger.formatMsg("[Filter:init] config_filter : ", cjson.encode(self.config_filter)))
   
end

function Filter:getFilterList()
    local retVal={}
    if ngx.var.APP_DEBUG_LOG== "true" then ngx.log(ngx.DEBUG,logger.formatMsg(string.format("config_filter is empty %s ",_.isEmpty(self.config_filter))))      end
    for i, val in ipairs(self.config_filter) do   
            if ngx.var.APP_DEBUG_LOG== "true" then ngx.log(ngx.DEBUG,logger.formatMsg(string.format("index=%s ,class=%s,method=%s",i,val["class"],val["method"])))     end
            table.insert(retVal,{ class = val["class"], method = val["method"] })       
    end
    if _.isEmpty(retVal) then
       return nil
    else
      return retVal
    end
  
end


return Filter